// 将函数式声明改为类声明
class Dispatcher {
  constructor() {
    this.listener = {};
  }
  
  on(event, fn) {
    if (!this.listener[event]) {
      this.listener[event] = [];
    }
    this.listener[event].push(fn);
  }
  
  off(event, fn) {
    if (this.listener[event]) {
      for (var i = 0; i < this.listener[event].length; i++) {
        if (this.listener[event][i] === fn) {
          this.listener[event].splice(i, 1);
          break;
        }
      }
    }
  }
  
  fire(event, data) {
    if (this.listener[event]) {
      for (var i = 0; i < this.listener[event].length; i++) {
        this.listener[event][i](data);
      }
    }
  }
}

// 只保留ES6导出
export default Dispatcher;